package com.meida.student.app.user.handler;

import com.meida.common.base.entity.EntityMap;
import com.meida.common.base.utils.FlymeUtils;
import com.meida.common.mybatis.model.PageParams;
import com.meida.common.mybatis.model.ResultBody;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.common.security.OpenHelper;
import com.meida.module.bbs.client.entity.BbsContent;
import com.meida.module.bbs.provider.handler.BaseBbsContentListHandler;
import com.meida.module.user.client.entity.AppUser;
import org.springframework.stereotype.Component;

/**
 * 帖子列表
 *
 * @author zyf
 */
@Component("bbsContentListHandler")
public class BbsContentListHandler extends BaseBbsContentListHandler {


    @Override
    public ResultBody validate(CriteriaQuery cq, EntityMap params) {
        return ResultBody.ok();
    }

    @Override
    public void prepare(CriteriaQuery<BbsContent> cq, PageParams pageParams, EntityMap params) {
        super.prepare(cq, pageParams, params);
        Long userId = OpenHelper.getUserId();
        Long schoolId = cq.getLong("schoolId");
        //前端分组标记1发现,2校园
        String contentGroup = cq.getParams("contentGroup");
        cq.ne("content.contentState", -1);
        if (FlymeUtils.isNotEmpty(contentGroup)) {
            if (contentGroup.equals("1")) {
                //不查询校园
                cq.ne("content.contentGroup", 2);
            }
            if (contentGroup.equals("2")) {
                //关联发布人学校ID
                cq.eq(true,"user.schoolId", schoolId);
            }
        }

    }


}
